
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Comedy Option
 */
public class EmpLeftSide extends JPanel{

    private static class CheckInButtonListener implements ActionListener {

        public CheckInButtonListener() {
        }

        @Override
        public void actionPerformed(ActionEvent e) {
                Reservation newReservation = new Reservation();
                newReservation.setFloorNumber(1);
                newReservation.setGuestIDNumber("11");
                newReservation.setGuestName("Bob Sagat");
                newReservation.setRoomNumber("Presidential Suite");
                EmpFacingView.getView().model.getFloorByName("1").getRoom("Presidential Suite").setCurrentOccupants(newReservation);
        }
    }
    
    
    private static class CheckOutButtonListener implements ActionListener{

        public CheckOutButtonListener(){
            
        }
        @Override
        public void actionPerformed(ActionEvent e) {
            EmpFacingView.getView().model.getFloorByName("1").getRoom("Presidential Suite").setCurrentOccupants(null);
        }
        
    }
    JLabel searchLabel;
    GridBagLayout gbl;
    JTextField searchText;
    JButton searchButton;
    JButton prevMatch;
    JButton nextMatch;
    JButton newReservation;
    JTextArea roomInfo;
    JLabel roomInfoLabel;
    JButton checkInGuest;
    JButton checkOutGuest;
    JButton editReservation;
    
    
    
    @SuppressWarnings("LeakingThisInConstructor")
    public EmpLeftSide(){
        gbl = new GridBagLayout();
        this.setLayout(gbl);
        this.setBackground(Color.LIGHT_GRAY);
        searchLabel = new JLabel("Find Guest:");
        layoutWithGBL(this, searchLabel, 0, 0, 1, 1);
        searchText = new JTextField(10);
        layoutWithGBL(this, searchText, 1, 0, 1, 1);
        searchButton = new JButton("Search");
        layoutWithGBL(this, searchButton, 2, 0, 1, 1);
        prevMatch = new JButton("< Previous Match");
        layoutWithGBL(this, prevMatch, 0, 1, 1, 1);
        nextMatch = new JButton("Next Match >");
        layoutWithGBL(this, nextMatch, 1, 1, 1, 1);
        newReservation = new JButton("New Guest");
        layoutWithGBL(this, newReservation, 2, 1, 1, 1);

        roomInfoLabel = new JLabel("Room Info:");
        layoutWithGBL(this, roomInfoLabel, 0, 2, 1, 1);
        roomInfo = new JTextArea(18, 30);
        roomInfo.setEnabled(false);
        roomInfo.setDisabledTextColor(Color.BLUE);
        layoutWithGBL(this, roomInfo, 0, 3, 3, 1);
        checkInGuest = new JButton ("Check In Guest");
        checkInGuest.addActionListener(new CheckInButtonListener());
        layoutWithGBL(this, checkInGuest, 0, 4, 1, 1);
        checkOutGuest = new JButton ("Check Out Guest");
        checkOutGuest.addActionListener(new CheckOutButtonListener());
        layoutWithGBL(this, checkOutGuest, 1, 4, 1, 1);
        editReservation = new JButton("Edit");
        layoutWithGBL(this, editReservation, 2, 4, 1, 1);
        for(int i = 0; i <10; i++){
            layoutWithGBL(this,new JLabel(""), 0, i+5, 1, 1);
        }
            
        
    }
    
    
    public static void layoutWithGBL(Container container, Component toAdd, int x, int y, int width, int height){
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.anchor = GridBagConstraints.PAGE_START;
        constraints.weighty = .5;
        constraints.gridwidth = width;
        constraints.gridheight = height;
        constraints.gridx = x;
        constraints.gridy = y;
        Insets gblInsets = new Insets(5, 5, 5, 5);
        constraints.insets = gblInsets;
        container.add(toAdd, constraints);
    }
    
    public void showRoomStuff(Room toShow){
        String roomNumber = toShow.getName();
        Double cost = toShow.getCost();
        int beds = toShow.getNumBeds();
        roomInfo.setText("Room: " + roomNumber + "\nRate: $" + cost + "\nNumber Of Beds: " + beds +"\nStatus: " + toShow.getCurrentStatus() + "\n");
        if(toShow.getCurrentOccupants()!= null){
            Reservation currentReservation = toShow.getCurrentOccupants();
            String guestId = currentReservation.getGuestIDNumber();
            String occupantName = currentReservation.getGuestName();
            Double owed = currentReservation.getTotalBill();
            roomInfo.append("Guest ID: " + guestId + "\nGuest Name: " + occupantName + "\nCurrent Bill: $" + owed);
        }
            
        
        
    }
    @Override
    public void paintComponent(Graphics g){
        super.paintComponent(g);
        

    }
}
